<!-- Form search -->
<?php echo $this->form?>

<!-- Data -->
<?php if (count($this->paginator)): ?>
<div class="data">
<?php $stats = array(
    'adr'   =>  0,
    'aur'   =>  0,
    'adm'   =>  0,
    'aum'   =>  0,
    'ads'   =>  0,
    'aus'   =>  0
); ?>
    <div class="front-view-data">
        <?php $COUNT = 1; ?>
        <table class="front-table">
            <thead>
            <th>#</th>
            <th><?php echo $this->translate('FRONT_ROUND')?></th>
            <th><?php echo $this->translate('FRONT_FIRST_CLUB')?></th>
            <th><?php echo $this->translate('FRONT_SECOND_CLUB')?></th>
            <th><?php echo $this->translate('FRONT_SCORES')?></th>
            <th><?php echo $this->translate('FRONT_RATIO_SCORES')?></th>
            <th><?php echo $this->translate("FRONT_TOTAL_SCORES") ?></th>
            <th><?php echo $this->translate('FRONT_RATIO_MONEY')?></th>
            <th><?php echo $this->translate("FRONT_OVER_UNDER")?></th>
            <th><?php echo $this->translate('FRONT_CHART')?></th>
            <th><?php echo $this->translate('FRONT_DATE')?></th>
        </thead>
        <?php foreach ($this->paginator as $game): ?>
            <?php
                $aur = FALSE;
                $adr = FALSE;
                $aum = FALSE;
                $adm = FALSE;
                $ads = FALSE;
                $aus = FALSE;

                //First club
                $goal1 = floatval($game->club1_scores);
                $arr = explode('-', $game->club1_rate);
                $sum_rate_1 = 0.0;
                if (!empty($arr[1])) {
                    $sum_rate_1 = floatval($arr[0]) + floatval($arr[1]);
                    $sum_rate_1 = $sum_rate_1/2;
                } else {
                    $sum_rate_1 = floatval($arr[0]);
                }
                $goal1 += $sum_rate_1;

                //Second club
                $goal2 = floatval($game->club2_scores);
                $arr = explode('-', $game->club2_rate);
                $sum_rate_2 = 0.0;
                if (!empty($arr[1])) {
                    $sum_rate_2 = floatval($arr[0]) + floatval($arr[1]);
                    $sum_rate_2 = floatval($sum_rate_2/2);
                } else {
                    $sum_rate_2 = floatval($arr[0]);
                }
                $goal2 += $sum_rate_2;

                // Rate
                if ((($sum_rate_1 > $sum_rate_2) && ($goal1 > $goal2)) ||
                    (($sum_rate_2 > $sum_rate_1) && ($goal2 > $goal1))) {
                    $stats['aur']++;
                    $aur = TRUE;
                }
                if ((($sum_rate_1 < $sum_rate_2) && ($goal1 > $goal2)) ||
                    (($sum_rate_2 < $sum_rate_1) && ($goal2 > $goal1))) {
                    $stats['adr']++;
                    $adr = TRUE;
                }

                // Money
                if ((($game->club1_mon > $game->club2_mon) && ($goal1 > $goal2)) ||
                    (($game->club2_mon > $game->club1_mon) && ($goal2 > $goal1))) {
                    $stats['aum']++;
                    $aum = TRUE;
                }
                if ((($game->club1_mon < $game->club2_mon) && ($goal1 > $goal2)) ||
                    (($game->club2_mon < $game->club1_mon) && ($goal2 > $goal1))) {
                    $stats['adm']++;
                    $adm = TRUE;
                }

                // Score
                $sc = floatval($game->club1_scores) + floatval($game->club2_scores);
                $arr = explode('-', $game->rscores);
                $rsc = 0;
                if (!empty($arr[1])) {
                    $rsc = floatval($arr[0]) + floatval($arr[1]);
                    $rsc = floatval($rsc/2);
                } else {
                    $rsc = floatval($arr[0]);
                }
                if ($rsc > $sc) {
                    $ads = TRUE;
                    $stats['ads']++;
                }
                if ($rsc < $sc) {
                    $aus = TRUE;
                    $stats['aus']++;
                }

                $class = '';
                if ($aur) {
                    $class .= 'aur ';
                }
                if ($adr) {
                    $class .= 'adr ';
                }
                if ($adm) {
                    $class .= 'adm ';
                }
                if ($aum) {
                    $class .= 'aum ';
                }
                if ($aus) {
                    $class .= 'aus ';
                }
                if ($ads) {
                    $class .= 'ads ';
                }

            ?>
            <tr class="<?php echo $class?>">
                <!-- COUNT -->
                <td class="front-order"><?php echo $COUNT ?></td>

                <!-- Round -->
                <td class="front-order-detail"><?php echo $game->round ?></td>

                <!-- First club name -->
                <?php
                    $c1Url = $this->pageUrl(array('action' => 'club', 'idc' => $game->id_club1), FALSE);
                ?>
                <td><a href="<?php echo $c1Url ?>">
                    <?php echo $game->club1_name ?>
                    </a>
                </td>

                <!-- Second club name -->
                <?php
                    $c2Url = $this->pageUrl(array('action' => 'club', 'idc' => $game->id_club2), FALSE);
                ?>
                <td><a href="<?php echo $c2Url?>">
                    <?php echo $game->club2_name ?>
                    </a>
                </td>

                <!-- Scores -->
                <td><?php echo $game->club1_scores . ' : ' . $game->club2_scores ?></td>

                <!-- Ratio -->
                <td><?php echo $game->club1_rate . ' : ' . $game->club2_rate ?></td>

                <!-- Up -->
                <td><?php echo $goal1.' : '.$goal2;?></td>

                <!-- Mon -->
                <td><?php echo $game->club1_mon . ' : ' . $game->club2_mon ?></td>

                <!-- Down -->
                <td><?php echo $game->rscores?></td>

                <!-- Chart -->
                <td class="td-chart"><img src="<?php echo IMAGE_URL.'/icons/chart.png'?>" />
                </td>

                <!-- Date -->
                <td class="front-date"><?php echo date('d-m-Y H:i', $game->date) ?></td>
            </tr>
            <?php $COUNT++ ?>
        <?php endforeach; ?>
        </table>
        <div class="front-pagination">
            <?php
                echo $this->paginationControl(
                        $this->paginator, 'Sliding', 'pagination_control.phtml', array(
                    'param_page' => PARAM_PAGE_NAME,
                    'query' => $this->query
                ));
            ?>
        </div>
    </div>
    <div class="front-data-stast">
        <table>
            <tr class="stats-aur">
                <td>AUR</td>
                <td><?php echo $stats['aur'] ?></td>
            </tr>
            <tr class="stats-adr">
                <td>ADR</td>
                <td><?php echo $stats['adr'] ?></td>
            </tr>

            <tr class="stats-aum">
                <td>AUM</td>
                <td><?php echo $stats['aum'] ?></td>
            </tr>
            <tr class="stats-adm">
                <td>ADM</td>
                <td><?php echo $stats['adm'] ?></td>
            </tr>

            <tr class="stats-aus">
                <td>AUS</td>
                <td><?php echo $stats['aus']?></td>
            </tr>
            <tr class="stats-ads">
                <td>ADS</td>
                <td><?php echo $stats['ads']?></td>
            </tr>
        </table>
    </div>
</div>

<div id="chart_dialog" style="display: none">
    aaa
</div>
<?php endif; ?>
<script>
    $(document).ready(function() {
        //AUR click
        $('.stats-aur').click(function(){
            $('.front-table tr').css('background-color', '#fff');
            $('.aur').css('background-color', 'crimson');
        });

        //ADR click
        $('.stats-adr').click(function(){
            $('.front-table tr').css('background-color', '#fff');
            $('.adr').css('background-color', 'coral');
        });

        //AUM click
        $('.stats-aum').click(function(){
            $('.front-table tr').css('background-color', '#fff');
            $('.aum').css('background-color', '#d1e6fd');
        });

        //ADM click
        $('.stats-adm').click(function(){
            $('.front-table tr').css('background-color', '#fff');
            $('.adm').css('background-color', 'cornflowerBlue');
        });

        //ADS click
        $('.stats-ads').click(function(){
            $('.front-table tr').css('background-color', '#fff');
            $('.ads').css('background-color', 'coral');
        });
        //AUS click
        $('.stats-aus').click(function(){
            $('.front-table tr').css('background-color', '#fff');
            $('.aus').css('background-color', 'activeborder');
        });

        //Chart
        $('.td-chart').click(function(){
            $('#chart_dialog').dialog();
        });

    });
</script>